<?php
if (!defined('NV_SYSTEM')) { die ("You can't access this file directly..."); }

require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
echo "<link rel=\"stylesheet\" type = \"text/css\" href = \"modules/".$module_name."/raovat.css\">";
require_once "modules/".$module_name."/functions.php";
get_lang($module_name);
if (file_exists("".$datafold."/config_".$module_name.".php")) {
	@require_once ("".$datafold."/config_".$module_name.".php");
}

function openBlock($title, $format){
	if($format==""){
		echo "<div class=\"Module\">"
		."<div class=\"headerMo\">"
		."	<b class=\"l\">"
		."	<b class=\"l1\"></b>"
		."	<b class=\"l2\"></b>"
		."	<b class=\"l3\"></b>"
		."	<b class=\"l4\"></b>"
		."	<b class=\"l5\"></b>"							
		."	</b>"
		."	<div class=\"content\">"
		.$title
		."	</div>"
		."</div>"
		."<div class=\"contentBox\">";
	}else{
		echo "<div class=\"Module\">"
		."<div class=\"headerMo1\">"
		."	<b class=\"l\">"
		."	<b class=\"l1\"></b>"
		."	<b class=\"l2\"></b>"
		."	<b class=\"l3\"></b>"
		."	<b class=\"l4\"></b>"
		."	<b class=\"l5\"></b>"							
		."	</b>"
		."	<div class=\"content\">"
		.$title
		."	</div>"
		."</div>"
		."<div class=\"contentBox1\">";
	}
}

function closeBlock(){
	echo "</div></div>";
}

function displayInfo($content){
	echo "<div class = \"quote\">";
	echo "<span style = \"font-size:12px;line-height:110%;\">";
	echo "$content\n";
	echo "</span>";
	echo "</div>";
}

		global $db, $user_prefix;
		if ((stristr($REQUEST_URI,"mainfile")) || (!isset($a_id))) { exit; }
    $id = intval($_GET['a_id']);
    
    $sql = "SELECT  "
      ." t1.item_id,"
      ." t1.user_id,"
      ." t1.ad_cat,"
      ." t1.title,"
      ." t1.content,"
      ." t1.add_time,"
      ." t1.expired_day,"
      ." t1.view_count,"
      ." t1.is_bad,"
      ." t1.is_checked,"
      ." t1.edit_ip, "
      ." t2.type_id,"
      ." t2.type_name,"
      ." t3.cat_name,"
      ." t4.area_name"
      ." FROM ad_item AS t1 "
      ." INNER JOIN ad_name AS t2 ON t1.ad_name = t2.type_id "
      ." INNER JOIN ad_cat AS t3 ON t1.ad_cat = t3.cat_id "
      ." INNER JOIN ad_area AS t4 ON t1.ad_area = t4.area_id "
      ." WHERE t1.item_id = $id LIMIT 1";
      //echo $sql;
    $ad_data = $db->sql_query($sql);
		if(mysql_num_rows($ad_data)<=0){
			//die("Fatal error : Bad Input");
			displayInfo(_KHONGTIMTHAY);
		}else{
			$row = $db->sql_fetchrow($ad_data);
			$uid = $row['user_id'];
			$udata = $db->sql_query("SELECT ".$user_prefix."_users.username FROM ".$user_prefix."_users WHERE ".$user_prefix."_users.user_id='$uid' ");
			if(mysql_num_rows($udata)>0) {
				$urow = $db->sql_fetchrow($udata);
				$uname = $urow['username'];
			}else {
				// die("Fatal error : No Matched user.";
				$uname = "";
			}
			openBlock(substr($row['title'],0,50)."..","1");
			$title = "<b> * "._TIEUDE." : </b><span style=\"color:#1E1498;\">".$row['title']."</span>";
			$title .= "<br><b> * "._NGAYDANG." : </b>".date("d/m/Y - g:i a",$row['add_time'])." - IP: ".$row['edit_ip'];
			$title .= "<br><b> * "._LINHVUC." : </b>".$row['cat_name'];
			$title .= "<br><b> * "._KHUVUC." : </b>".$row['area_name'];
			$title .= "<br><b> * "._SOLANXEM." : </b>".$row['view_count'];
			$time_passed = time() - intval($row['add_time']);
			$days_passed = intval($time_passed/86400);
			if($days_passed > $max_exp || $days_passed > intval($row['expired_day'])){
				$status = _HETHIEULUC;
			}else{
				$dayleft = intval($row['expired_day']) - $days_passed ;
				$status = $dayleft._NGAY;
			}
			$title .= "<br><b> * "._THOIHANHIEULUC." : </b>".$status;
			$title .= "<br><b> * "._NGUOIDANG." : ".$uname;
			if($id !=0) displayInfo($title);
			
			$post_message = $row['content'];
			$post_message = format_bbcodes($post_message);
			$post_message = fix_tabs_spaces($post_message);

			displayInfo($post_message);
			closeBlock();
			
			echo "
			<font size=\"2\"><a href=\"javascript:window.print();\" onClick=\"varitext()\">PRINT</a> | <a href=\"\" onclick=\"window.close();\">CLOSE</a></font>
			</body>
			</html>";
		}

?>
